package com.linwen.excise.leetcode;

/**
 * @ClassName _55跳跃游戏
 * @Description TODO
 * @Author zero
 * @DATE 2024/4/7 11:26 PM
 * @Version 1.0
 */
public class _55跳跃游戏 {
    public static void main(String[] args) {
        int[] arr = {2,3,1,1,4};
        System.out.println(canJump(arr));
    }
    public static boolean canJump(int[] nums) {
        int target = nums.length-1;
        int max = nums[0];
        for (int i = 0; i < nums.length; i++) {
            if(max>=target) {
                return true;
            }
            max = Math.max(nums[i]+i,max);
            if(max==i){
                return false;
            }
        }
        return true;
    }
}
